<?php


/**
 * Description of AppConfiguration:
 * Reads application configuration from the configuration file and created 
 * members functions to access the database
 *
 * @author Malekgene Rantho
 * @date 24 May 2011
 */
class AppConfiguration {
    
    //Database user username
    private $db_username;
    //Database user password
    private $db_password;
    //Database host
    private $db_host;
    //Database name
    private $db_name;
    //Database table
    private $db_table;
    
    //Class file path
    private $class_path;
    //Images/logos file path
    private $image_path;
    //Theme path
    private $theme_path;
    //Theme file name
    private $theme_filename;


    //Web domain name
    private $web_domain;
    //Application url
    private $web_url;
    

    //Class constructor
    function __construct(){
        
          //Include Pear config class
          require_once("Config.php");
          //Create reference to read xml file
          $template = new Config;
          //Xml base directory
          $baseDir = "/var/www/testxmlSonia/";
          //create a reference to the xml contents and pass the file
          $root =& $template->parseConfig($baseDir.'websettings.xml', 'XML');
          //Check if the file opened successfully or with errors
          if (PEAR::isError($root)) {
          die('Error while reading configuration: ' . $root->getMessage());
           }

          //Create xml root reference
          $appConfig =& $root->getItem("section","websettings");
          
          //Create reference to database host element
          $host =& $appConfig->getItem("directive","database_host");
          //Read database host element attribute value
          $this->db_host = $host -> getContent();
        
          //Create reference to database user username element
          $userName =& $appConfig ->getItem("directive","database_username");
          //Read username element attribute value
          $this->db_username=$userName->getContent();
          
          //Create reference to the database user password element
          $password =& $appConfig->getItem("directive","database_password");
          //Read username element attribute value 
          $this->db_password=$password->getContent();
          
          //Create reference to the database name element
          $name =& $appConfig -> getItem("directive","database_name");
          //Read database name element attribute value
          $this->db_name=$name->getContent();
          
          //Create reference to the database table element          
          $table =& $appConfig ->getItem("directive","database_table");
          //Read database table element attribute value
          $this->db_table=$table->getContent();
          
          //Create reference to the class path element
          $class =& $appConfig->getItem("directive", "class_path") ;
          //Read class path element
          $this->class_path=$class->getContent();
          
          //Create reference to the image path element
          $image =& $appConfig->getItem("directive","image_path");
          //Read image path value
          $this->image_path=$image->getContent();
          
          //Create reference to the theme path element
          $theme =& $appConfig->getItem("directive","theme_path");
          //Read theme path value
          $this->theme_path=$theme->getContent();
          
          //Create reference to the theme path element
          $theme =& $appConfig->getItem("directive","theme_filename");
          //Read theme path value
          $this->theme_filename=$theme->getContent();
          
          //Create reference to the web domain element
          $domain =& $appConfig->getItem("directive","web_domain");
          //Read web domain value
          $this->web_domain=$domain->getContent();
          
          //Create reference to the web url
          $url =& $appConfig->getItem("directive","web_url");
          //Read web url value
          $this->web_url=$url->getContent();
           
          
    }
    
    //Return an array of database connection settings 
    public function getDatabaseConnectionSettings()
    {
        
       $dbArray = array($this->db_host,$this->db_name, $this->db_password,$this->db_table,$this->db_username);
        return $dbArray;
        
    }
    
    //Return class path value
    public function getClassPath()
    {
        $filePath = $this->class_path;
        return $filePath;
    }
    
    //Return image path value
    public  function getImagePath()
    {
        $imagePath = $this->image_path;
        return $imagePath;
    }
    
    //Return theme path value
    public function getThemePath()
    {
        $themePath = $this->theme_path;
        return $themePath;
    }
    
    //Returm web domain value
    public function getWebDomain()
    {
        $webDomain = $this->web_domain;
        return $webDomain;
    }
    
    //Return web url value
    public function getWebUrl()
    {
        $webUrl = $this->web_url;
        return $webUrl;
    }
    
    //Return filename of the xml file that stores theme name
    public function getThemeFileName()
    {
        $themeFile = $this->theme_filename;
        return $themeFile;
        
    }
    
}

?>
